(function() {
    // 创建水印容器
    var watermarkContainer = document.createElement('div');
    watermarkContainer.style.position = 'fixed';
    watermarkContainer.style.top = '0';
    watermarkContainer.style.left = '0';
    watermarkContainer.style.width = '100%';
    watermarkContainer.style.height = '100%';
    watermarkContainer.style.pointerEvents = 'none';
    watermarkContainer.style.zIndex = '9999';
    
    // 水印样式设置
    function createWatermark() {
        var watermarkText = '我是页面水印。。';
        var watermarkDiv = document.createElement('div');
        watermarkDiv.style.position = 'absolute';
        watermarkDiv.style.color = 'rgba(255, 0, 0, 0.4)'; // 调整颜色和透明度
        watermarkDiv.style.fontSize = '20px'; // 字体大小
        watermarkDiv.style.transform = 'rotate(-45deg)'; // 旋转角度
        watermarkDiv.style.whiteSpace = 'nowrap';
        watermarkDiv.innerText = watermarkText;
        return watermarkDiv;
    }

    // 根据屏幕大小填充水印
    function fillWatermarks() {
        // 清空之前的水印
        watermarkContainer.innerHTML = '';
        var screenWidth = window.innerWidth;
        var screenHeight = window.innerHeight;
        var watermarkWidth = 200; // 水印宽度
        var watermarkHeight = 100; // 水印高度

        for (var x = 0; x < screenWidth; x += watermarkWidth) {
            for (var y = 0; y < screenHeight; y += watermarkHeight) {
                var watermarkDiv = createWatermark();
                watermarkDiv.style.left = x + 'px';
                watermarkDiv.style.top = y + 'px';
                watermarkContainer.appendChild(watermarkDiv);
            }
        }
    }

    // 当窗口大小改变时，重新填充水印
    window.onresize = fillWatermarks;

    document.body.appendChild(watermarkContainer);
    fillWatermarks(); // 初始填充水印
})();
